/**
 * Created by dylan_Apple on 17/6/19.
 * 晨会信息表
 */
var Waterline = require('waterline');
var uuid = require('node-uuid');
var moment = require('moment');

/**
 * @type {void|*}
 */
module.exports = Waterline.Collection.extend({
    identity: 'search',
    tableName: 'tb_search',
    connection: "mysql",
    attributes: {

        rowId: {
            type: 'string',
            primaryKey: true,
            unique: true,
            required: true,
            uuidv4: true,
            columnName: 'rowid',
            defaultsTo: function () {
                return uuid.v4();
            }
        },
        val: {
            type: 'string',
            columnName: 'val',
        },
        title: {
            type: 'string',
            columnName: 'title',
        },
        createUid: {
            type: 'string',
            required: true,
            columnName: 'createUid',
            model: 'user'
        },
        time: {
            type: 'string',
            required: true,
            columnName: 'time'
        },
        channel: {
            type: 'string',
            columnName: 'channel'
        },
        toJSON: function () {
            var obj = this.toObject();
            obj.createdAt = moment(obj.createdAt).format('YYYY-MM-DD HH:mm');
            obj.time =  moment(obj.time).format('YYYY-MM-DD');
            obj.updatedAt = moment(obj.updatedAt).format('YYYY-MM-DD HH:mm');
            return obj;
        }

    }
});
